
$(function() {

    //注册登录
    new configure().theNextRegister();

    $("#tel")[0].focus();
    //获取短信验证码
    var validCode=true;
    $(".msgs").click (function  () {
        var tel= $("#tel").val();//手机号
        if(tel==""){
            $.toast('请输入手机号', 'forbidden'); return;
        }
        if(tel.length!=11){
            $.toast('请输入正确手机号', 'forbidden');return;
        }
        var params={};
        params.mobile=tel;
        var time=60; //60秒
        if (validCode) {
            validCode=false;
            $(".msgs").css("color","#818080");
            var params={};
            params.mobile=tel;
            params.msg_type=0;
            new configure().connect("https://o2o.96225.com/city/index.php/home/api/sendCap_Code","POST",params,function (data,status,txtErr) {
                if(status=="success"){
                    if(data.code==0){
                        $.toptip(data.msg);
                        var t=setInterval(function  () {
                            time--;
                            $(".msgs").html(time+"秒");
                            if (time==0) {
                                clearInterval(t);
                                $(".msgs").html("重新获取");
                                validCode=true;
                                $(".msgs").css("color","#04be02");
                            }
                        },1000)
                    }else{
                        $.toptip(data.msg);
                    }
                }else{
                    $.toptip(txtErr);
                }

            })

        }

    })


    $("#showTooltips").click(function() {
        var user_id = $('#tel').val();
        var veri_code = $('#code').val();
        var password = $('#pwd').val();

        if(user_id==""){
            $.toast('请输入手机号', 'forbidden'); return;
        }
        if(user_id.length!=11){
            $.toast('请输入正确手机号', 'forbidden');return;
        }
        else if(!veri_code || !/\d{6}/.test(veri_code)) {$.toast('请输入六位手机验证码', 'forbidden');return;}
        else if(!((/^[\w]{6,20}$/.test(password)) && !(/^\d+$/.test(password)) && !(/^[A-Za-z]+$/.test(password)))){$.toast('请设置6~20位数字和字母组合的密码', 'forbidden');return;}
        //注册
        var params={};
        params.veri_code=veri_code;
        params.user_id=user_id;
        params.type=0;
        params.password=password;
        params.user_system=new configure().getUrlParam("user_system");

        new configure().connect(new configure().url_smk+"javaapi/smkuser-service/users/registe","POST",params,function (data,status,txtErr) {
            if(status=="success"){

                if(data.code==0000){
                    $.toast('注册成功', 'ok')
                    window.location.href=window.localStorage.getItem("callback_url");
                }else{
                    $.toptip(data.msg);
                }
            }else{
                $.toptip(txtErr);
            }
        })
    });

});



